package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IMediationTemplateService;
import com.mdd.admin.validate.MediationTemplateCreateValidate;
import com.mdd.admin.validate.MediationTemplateSearchValidate;
import com.mdd.admin.validate.MediationTemplateStateUpdateValidate;
import com.mdd.admin.validate.MediationTemplateUpdateValidate;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.MediationTemplateDetailVo;
import com.mdd.admin.vo.MediationTemplateListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/template")
@Api(tags = "调解书模板管理")
public class MediationTemplateController {

    @Resource
    IMediationTemplateService iMediationTemplateService;

    @GetMapping("/list")
    @ApiOperation(value="调解书模板列表")
    public AjaxResult<PageResult<MediationTemplateListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated MediationTemplateSearchValidate searchValidate) {
        PageResult<MediationTemplateListedVo> list = iMediationTemplateService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="调解书模板详情")
    public AjaxResult<MediationTemplateDetailVo> detail(@Validated @IDMust() @RequestParam("templateNumber") Integer templateNumber) {
        MediationTemplateDetailVo detail = iMediationTemplateService.detail(templateNumber);
        return AjaxResult.success(detail);
    }

    @Log(title = "调解书模板新增")
    @PostMapping("/add")
    @ApiOperation(value="调解书模板新增")
    public AjaxResult<Object> add(@Validated @RequestBody MediationTemplateCreateValidate createValidate) {
        iMediationTemplateService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "调解书模板编辑")
    @PostMapping("/edit")
    @ApiOperation(value="调解书模板编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody MediationTemplateUpdateValidate updateValidate) {
        iMediationTemplateService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "调解书模板状态编辑")
    @PostMapping("/editState")
    @ApiOperation(value="调解书模板编辑")
    public AjaxResult<Object> editState(@Validated @RequestBody MediationTemplateStateUpdateValidate updateValidate) {
        iMediationTemplateService.editState(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "调解书模板删除")
    @PostMapping("/del")
    @ApiOperation(value="调解书模板删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iMediationTemplateService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
